﻿//获得IE版本
function getIEVersonNumber() {
	var ua = navigator.userAgent;
	var msieOffset = ua.indexOf("MSIE ");
	if(msieOffset < 0) {
		return 0;
	}
	return parseFloat(ua.substring(msieOffset + 5, ua.indexOf(";", msieOffset)));
};

function Loginname() {
	$(".focusText .text_enter").each(function() {
		var thisVal = $(this).val();
		if(thisVal != "") {
			$(this).siblings("span").hide();
		} else {
			$(this).siblings("span").show();
		}
		$(this).focus(function() {
			$(this).siblings("span").hide();
		}).blur(function() {
			var val = $(this).val();
			if(val != "") {
				$(this).siblings("span").hide();
			} else {
				$(this).siblings("span").show();
			}
		});
	});
};

function SetHome(obj, url) {
	try {
		obj.style.behavior = 'url(#default#homepage)';
		obj.setHomePage(url);
	} catch(e) {
		if(window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			} catch(e) {
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage', url);
		} else {
			alert("您所用的浏览器无法完成次操作请手动设为首页！");
		}
	}
};

function setHomepage() {
	if(document.all) {
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage(window.location.href);
	} else if(window.sidebar) {
		if(window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			} catch(e) {
				alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage', window.location.href);
	} else {
		alert('您的浏览器不支持自动自动设置首页, 请使用浏览器菜单手动设置!');
	}
};

function UserCodeKeyDown() {
	if(event.keyCode == 13) {
		if($('#UserCode').val() == '') {
			return false;
		}
		$('#UserPwd').focus();

	}
};

function UserPwdKeyDown() {
	if(event.keyCode == 13) {
		if($('#UserPwd').val() == '') {
			return false;
		}
		$('#BtnLogin').click();

	}
};

function UserLogin() {
	alert("2222");
};
//打开主窗口
//可能要加Win参数。
function openMainWin() {
	var id = document.all.id.value;
	var password = document.all.password.value;
	var value = document.all.tb_check.value;
	var cb_saveid = document.all.cb_saveid.checked;
	var rad = Math.random()
	postAjax(getUrlBase() + '/AjaxServ.aspx?Action=SetPassword&SearchValue=' + escape(password));
	var url = "Dispatch.aspx?Action=Login&id=" + id + "&Dispatch=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi" + rad + "jklmnopqrstuvwxyz&check=" + value + "&cb_saveid=" + cb_saveid;

	var winname;
	if(top.name != 'KEMAI_Main') {
		winname = 'KEMAI_Main';
	} else {
		winname = 'KEMAI_Main1'
	}
	try {

		window.open(url, winname, 'height=' + (window.screen.height - 60) + ', width=' + (window.screen.width - 10) + ', top=0, left=0, menubar=0, location=0, resizable=0, status=1');

		var oMe = window.self;
		oMe.opener = null;
		oMe.open('', '_self');
		oMe.close();
	} catch(e) {
		alert(e);
	}
	return true;
}

function onKeyDown() {
	if(event.keyCode == 13) {
		if(event.srcElement.id == "id") {
			document.all.password.focus();
			return false;
		}
		if(event.srcElement.id == "password") {
			document.all.tb_check.focus();
			return false;
		}
		openMainWin();
	}
	if(event.keyCode == 27) {
		window.close();
	}
}

//华耐立家建材连锁前端销售系统
function initApp(appName) {
	var isIE = (navigator.appName == "Microsoft Internet Explorer");
	if(isIE && getIEVersonNumber() >= 6) {
		if(document.all.id) {
			document.all.id.select();
			document.all.id.focus();
		}
		if(window.screen.width < 768) {
			alert(appName + "正常运行至少需要800x600的屏幕分辨率，建议使用1024x768的屏幕分辨率。\n请调节显示分辨率。")
			window.close();
		}
	} else {
		alert(appName + "正常运行需要Microsoft Internet Explorer浏览器6.0及以上版本!\n请安装或升级 Microsoft Internet Explorer 浏览器后重试.");
		window.opener = null;
		window.close();
	}
	document.attachEvent("onkeydown", onKeyDown);
}